package com.zju.DoctorGo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zju.DoctorGo.dto.DoctorDTO;
import com.zju.DoctorGo.dto.UserEditPasswordDTO;
import com.zju.DoctorGo.dto.UserUnregisterDTO;
import com.zju.DoctorGo.entity.Doctor;
import com.zju.DoctorGo.entity.User;
import com.zju.DoctorGo.dto.UserLoginDTO;
import com.zju.DoctorGo.mapper.BillMapper;
import com.zju.DoctorGo.mapper.DoctorMapper;
import com.zju.DoctorGo.service.DoctorYellowPageService;
import com.zju.DoctorGo.service.UserService;
import com.zju.DoctorGo.utils.EmailVerifyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DoctorYellowPageServiceImpl extends ServiceImpl<DoctorMapper, Doctor> implements DoctorYellowPageService {
    @Autowired
    private DoctorMapper doctorMapper;
    /*
     * 创建一个医生
     */
    public void createDoctor(Doctor doctor){
        this.save(doctor);
    }

    
    public Integer getByName(String doctorName){
        Integer doctorId = doctorMapper.retrieveDoctorId(doctorName);
        if (doctorId == null || doctorId == 0){
            throw new RuntimeException("医生名字不存在");
        }
        return doctorId;
    }
    /*
     * 查询医生信息
     */
    public Doctor retrieveDoctorById(Integer doctorId){
        Doctor doctor = doctorMapper.retrieveDoctorById(doctorId);
        if (doctor == null){
            throw new RuntimeException("医生ID不存在");
        }
        return doctor;
    }
    /*
     * 用在查询科室，选择医生上，可结合retrieveDoctorById获得完整信息
     */
    public List<DoctorDTO> retrieveDoctorsBySpecialty(String specialty){
        if (specialty == null || specialty.trim().isEmpty()) {
            throw new IllegalArgumentException("Specialty cannot be null or empty");
        }
        List<DoctorDTO> doctors = doctorMapper.retrieveDoctorsBySpecialty(specialty);
        if (doctors == null || doctors.isEmpty()){
            throw new RuntimeException("科室不存在");
        }
        return doctors;
    }
    /*
     * 返回完整的医生信息，用于黄页
     */
    public List<Doctor> retrieveDoctorsBySpecialty2(String specialty){
        if (specialty == null || specialty.trim().isEmpty()) {
            throw new IllegalArgumentException("Specialty cannot be null or empty");
        }
        List<Doctor> doctors = doctorMapper.retrieveDoctorsBySpecialty2(specialty);
        if (doctors == null || doctors.isEmpty()){
            throw new RuntimeException("科室不存在");
        }
        return doctors;
    }

}


